<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="com.ionglobal.db.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ionglobal.lib.*" %>
<%@page import="com.gzgi.weqs.basedata.SupplierApp"%>
<%@page import="com.gzgi.weqs.basedata.Supplier"%>
<%@page import="com.gzgi.weqs.basedata.SupplierDB"%>
<%@page import="org.json.*"%>
<%@ include file="/include/init_include.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
int pageNo = Request.getInt("page",1);
int pageSize = Request.getInt("pageSize",20);
%>
<% 
   
   String mothod = request.getParameter("mothod").toString() ;
   SupplierApp suppapp = new SupplierApp() ;
   JSONObject jsonObject = new JSONObject();
   if(mothod.equals("list")){
      //SupplierApp suppapp = new SupplierApp() ;
      String search=Request.getString("search");
      out.print(suppapp.ListJoson(dbi,pageNo,pageSize,search)) ;
   }else if(mothod.equals("add")){
     //JSONObject jsonObject = new JSONObject();
      Supplier supp = new Supplier() ;
      SupplierDB suppdb = new SupplierDB() ;
      //SupplierApp suppapp = new SupplierApp();
      String suppno = Request.getString("ssupplierno") ;
      supp.setSupplierNo(Request.getString("ssupplierno"));
      supp.setSupplierFName(Request.getString("ssupplierfname")) ;
      supp.setSupplierSName(Request.getString("ssuppliersname")) ;
      supp.setPhone(Request.getString("sphone"));
      supp.setFax(Request.getString("sfax")) ;
      supp.setMobilePhone(Request.getString("smobilephone")) ;
      supp.setLinkMan1(Request.getString("slinkman1")) ;
      supp.setLinkTel1(Request.getString("slinktel1")) ;
      supp.setLinkMan2(Request.getString("slinkman2")) ;
      supp.setLinkTel2(Request.getString("slinktel2")) ;
      supp.setMail(Request.getString("smail")) ;
      supp.setAddress(Request.getString("saddress")) ;
      supp.setIsYCZG(Request.getInt("hyczg")) ;
      supp.setIsDQCT(Request.getInt("hdqtc"));
      supp.setTcMonth(Request.getString("hmonth")) ;
      if(suppapp.getSupplier(dbi,suppno)==null){
        if(suppdb.insertSupplier(dbi,supp)){
		   jsonObject.put("errorCode", "1");
	     }else{
	       jsonObject.put("errorCode", "2");
	     }
       out.print(jsonObject);
      }else{
         if(suppapp.updateSupplier(dbi,supp,suppno)){
		   jsonObject.put("errorCode", "3");
	     }else{
	       jsonObject.put("errorCode", "4");
	     }
       out.print(jsonObject);
      }
      
   }else if(mothod.equals("delete")){
     String suppno = Request.getString("id") ;
     if(suppapp.delete(dbi,suppno)){
          jsonObject.put("errorCode", "5");
     }else{
          jsonObject.put("errorCode", "6");
     }
     out.print(jsonObject);
   }
      
%>
<%@ include file="/include/init_free.jsp" %>